﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Data;
using MODEL;
namespace DAL
{
    public class BoardDAL
    {
        private static readonly string SELECT_BOARD = "select BoardId,status from Board where status =@status";

        public List<BoardInfo> GetBoardList(int status)
        {


            List<BoardInfo> list = new List<BoardInfo>();
            DataTable dt = new DataTable();
            dt = ExcuteSqlText(SELECT_BOARD, status);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                BoardInfo board = new BoardInfo(Convert.ToInt32(dt.Rows[i]["BoardId"]), Convert.ToInt32(dt.Rows[i]["status"]));
                list.Add(board);
            }

            return list;
        }


        private DataTable ExcuteSqlText(string sqlText, int param)
        {
            try
            {
                DataTable dt = new DataTable();
                Database db = null;
                db = DatabaseFactory.CreateDatabase();
                DbCommand cmd = db.GetSqlStringCommand(sqlText);
                db.AddInParameter(cmd, "@status", DbType.Int32, param);
                return db.ExecuteDataSet(cmd).Tables[0];
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
